@file:JvmName("main")

package me.duyu.tools

import io.vertx.core.Vertx
import io.vertx.core.VertxOptions
import io.vertx.core.http.HttpServerOptions
//import java.io.File;


fun main(args : Array<String>) {
    val options = VertxOptions();
    options.setEventLoopPoolSize(2);
    options.setWorkerPoolSize(2);
//    var json = options.toString();
//    var file = File("config.json").outputStream()
//    file.write(json.toByteArray())
    val vertx = Vertx.vertx(options);
    val httpOptions = HttpServerOptions();
    httpOptions.maxHeaderSize = 4 * 1024;
    val router = buildRouter(vertx);

    val fsys = vertx.fileSystem()
    if(!fsys.existsBlocking("clients"))
        fsys.mkdirBlocking("clients")

    println("start Server Main listen the server in 8082");
    val mainServer = vertx.createHttpServer(httpOptions);
    mainServer.requestHandler(router::accept).listen(8186);

    // 开启多个线程处理eventloop
    for (i in 0 until options.eventLoopPoolSize) {
        println("start Server $i listen the server in 8082");
        val server = vertx.createHttpServer(httpOptions);
        server.requestHandler(router::accept).listen(8186);
    }
    println("main run end!!!");
}

/**
{
    "eventLoopPoolSize": 2,
    "workerPoolSize": 2,
    "internalBlockingPoolSize": 20,
    "blockedThreadCheckInterval": 1000,
    "maxEventLoopExecuteTime": 2000000000,
    "maxWorkerExecuteTime": 60000000000,
    "clusterManager": null,
    "haEnabled": false,
    "fileCachingEnabled": true,
    "preferNativeTransport": false,
    "quorumSize": 1,
    "haGroup": "__DEFAULT__",
    "metrics": {
        "enabled": false,
        "json": null
    },
    "addressResolver": {
        "cacheMaxTimeToLive": 2147483647,
        "cacheMinTimeToLive": 0,
        "cacheNegativeTimeToLive": 0,
        "maxQueries": 4,
        "ndots": 1,
        "optResourceEnabled": true,
        "queryTimeout": 5000,
        "rdFlag": true,
        "rotateServers": false
    },
    "eventbus": {
        "acceptBacklog": -1,
        "clientAuth": "NONE",
        "clusterPingInterval": 20000,
        "clusterPingReplyInterval": 20000,
        "clusterPublicPort": -1,
        "clustered": false,
        "connectTimeout": 60000,
        "crlPaths": [ ],
        "crlValues": [ ],
        "enabledCipherSuites": [ ],
        "enabledSecureTransportProtocols": [ ],
        "host": "localhost",
        "idleTimeout": 0,
        "logActivity": false,
        "port": 0,
        "receiveBufferSize": -1,
        "reconnectAttempts": 0,
        "reconnectInterval": 1000,
        "reuseAddress": true,
        "reusePort": false,
        "sendBufferSize": -1,
        "soLinger": -1,
        "ssl": false,
        "tcpCork": false,
        "tcpFastOpen": false,
        "tcpKeepAlive": false,
        "tcpNoDelay": true,
        "tcpQuickAck": false,
        "trafficClass": -1,
        "trustAll": true,
        "useAlpn": false,
        "usePooledBuffers": false
    },
    "warningExceptionTime": 5000000000
}
 **/